﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BookShop3Tables.Models;
using BookShop3Tables.ViewModels;
using BookShop3Tables.DAL;

namespace BookShop3Tables.Controllers
{
    public class HomeController : Controller
    {
        private BookContext db = new BookContext();

        public ActionResult Index()
        {
            ViewBag.Message = "Book Shop";

            return View();
        }

        public ActionResult About()
        {
            var data = from book in db.Books
                       group book by book.ReleaseDate into dateGroup
                       select new CategoryAndBooks()
                       {
                           ReleaseDate = dateGroup.Key,
                           BookCount = dateGroup.Count()
                       };
            return View(data);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}
